           package controller;


import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import AccessDB.AvaliacaoDAO;
import AccessDB.BimestreDAO;
import AccessDB.CalendarioDAO;
import AccessDB.ConnectionDB;
import AccessDB.DisciplinaProfessorDAO;
import AccessDB.ProfessorDAO;
import AccessDB.TurmaDAO;


import model.Aluno;
import model.Avaliacao;
import model.Bimestre;
import model.DisciplinaProfessor;
import model.Professor;
import model.Turma;
import model.Usuario;


public class NavegacaoProfessorServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
    public NavegacaoProfessorServlet() {
        super();
        
    }
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String pagina = request.getParameter("pagina");
		HttpSession session = request.getSession();
		if(pagina.equalsIgnoreCase("gerenciar_turmas")){
			

			
			String cpfProf = ((Professor) session.getAttribute("usuario")).getCpf();
			
			try {
				List<DisciplinaProfessor> disciplinasProf = new DisciplinaProfessorDAO().recuperarTituloDasDisciplinasDoProfessor(cpfProf);
				
				request.setAttribute("disciplinasProf", disciplinasProf);
				RequestDispatcher dispatcher = request.getRequestDispatcher("professor/turmas.jsp");
	    		dispatcher.forward(request, response);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		else if(pagina.equalsIgnoreCase("visualizar_turma"))
		{
			int idDisciplinaProf = Integer.parseInt(request.getParameter("idDisciplinaProf"));
			int idTurma = Integer.parseInt(request.getParameter("idTurma"));

			try {
				DisciplinaProfessor discProf = new DisciplinaProfessorDAO().gerarDisciplinaProfessor(idDisciplinaProf, idTurma);
				session.setAttribute("discProf", discProf);
				RequestDispatcher dispatcher = request.getRequestDispatcher("professor/visualizar_turma.jsp");
	    		dispatcher.forward(request, response);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return;
		}		
		else if(pagina.equalsIgnoreCase("lista_alunos")){
			RequestDispatcher dispatcher = request.getRequestDispatcher("professor/lista_alunos.jsp");
    		dispatcher.forward(request, response);
    		return;
		}
		
		else if(pagina.equalsIgnoreCase("atividades")){

			int ano = (Integer)((DisciplinaProfessor) session.getAttribute("discProf")).getAno();
			try {
				List<Bimestre> bimestres = new BimestreDAO().retornaBimestresDoAno(ano);
				request.setAttribute("bimestres", bimestres);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			RequestDispatcher dispatcher = request.getRequestDispatcher("professor/atividades.jsp");
    		dispatcher.forward(request, response);
    		return;
		}
		
		else if(pagina.equalsIgnoreCase("enviar_material_download")){
			RequestDispatcher dispatcher = request.getRequestDispatcher("professor/enviar_material_download.jsp");
    		dispatcher.forward(request, response);
    		return;
		}
		
		else if(pagina.equalsIgnoreCase("enviar_msg_turma")){
			RequestDispatcher dispatcher = request.getRequestDispatcher("professor/enviar_msg_turma.jsp");
    		dispatcher.forward(request, response);
    		return;
		}
		else if(pagina.equalsIgnoreCase("calendario"))
		{
			try {
				
				String caminho = new CalendarioDAO().retornaUltimoCalendarioDoAno(2009);
				
				if(caminho != null)
					request.setAttribute("caminho", caminho);
				else
					request.setAttribute("caminho", "nenhum");
				
				RequestDispatcher dispatcher = request.getRequestDispatcher("professor/calendario.jsp");
				dispatcher.forward(request, response);
				
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
				
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

}
